package com.example.sid.utils

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlin.properties.Delegates

object Utils {
	//Все слушатели были сделаны исключительно в иллюстрационных целях.
	private var isInitialized by Delegates.observable(false){ _,_,newValue ->
		listenerList.forEach { listener ->
			listener.invoke(newValue)
		}
	}

	private val listenerList = mutableListOf<(Boolean) -> Unit>()

	fun setInitialized(){
		isInitialized = true
	}

	fun getInitialized() = isInitialized

	fun getInitializeListener(listener: (Boolean) -> Unit) {
		listenerList.add(listener)
		listener.invoke(getInitialized())
	}

	fun removeInitializeListener(listener: (Boolean) -> Unit){
		listenerList.remove(listener)
	}

	val main = CoroutineScope(Dispatchers.Main)
	val ioScope = CoroutineScope(Dispatchers.IO)
	val defaultScope = CoroutineScope(Dispatchers.Default)
}